

use "$clean/clean_all.dta" ,clear


cap gen coeff=. in 1/13
cap gen u_se=. in 1/13
cap gen l_se=. in 1/13
cap gen coeff_t=. in 1/13
cap gen u_se_t=. in 1/13
cap gen l_se_t=. in 1/13
cap gen time_week=_n in 1/13



*** Use pre-treatment weeks ***

forval l=2/4 {
local k=5-`l'
local q=5-`l'+1
egen temp=rowmax(canvass_any_n`k'week canvass_any_n`q'week)
replace canvass_any_n`k'week= temp
drop temp
}


egen temp=rowmax(canvass_any_n1week canvass_any_0week)
replace canvass_any_0week= temp
drop temp

forval l=1/8 {
local k=`l'-1
egen temp=rowmax(canvass_any_`k'week canvass_any_`l'week)
replace canvass_any_`l'week= temp
drop temp
}


gen id=_n

expand 13

bys id: gen time=_n

gen temp_week = . 
forval l = 1/4 {
local k = 5 -`l' 
replace temp_week = canvass_any_n`k'week if time==`l'

}

forval l = 5/13 {
local k = `l'-5
replace temp_week = canvass_any_`k'week if time==`l'

}


reghdfe temp_week  ib5.time##i.treatment , cluster(id) absorb(id)


forval l=1/13 {
replace coeff=_b[1.treatment#`l'.time] in `l'
replace u_se=_b[1.treatment#`l'.time]+1.96*_se[1.treatment#`l'.time] in `l'
replace l_se=_b[1.treatment#`l'.time]-1.96*_se[1.treatment#`l'.time] in `l'
}

replace coeff=0 in 5
replace u_se=. in 5
replace l_se=. in 5

drop if time_week>13

twoway line coeff time || rcap u_se l_se time ///
 , ytitle("Treatment effect on any canvassing", ) xtitle("Weeks relative to treatment")  ///
 , legend(order( 1 "Treatment effect" ///
2 "95% CI"  ) pos(6) rows(1)) ///
ysc(range(-0.075 0.05)) ylab(-0.05(0.05)0.05) xlab( 1 "-4" 2 "-3" 3"-2" 4 "-1" 5 "0" 6"1" 7"2" 8"3" 9"4" 10"5" 11"6" 12"7" 13 "8" ) ///
xsc(range(1 13))    xline(5, lcolor(red))


graph export "$figures/Figure_A5.pdf",  replace as(pdf)






